(($) ->
  Huxi =
    init: ->
      self = this
      Bootup = ->
        self.siteBootup()
        return
      PageUpdate = ->
        self.sitePageUpdate()
        return
      PageRestore = ->
        self.sitePageRestore()
        return
      PageFetch = ->
        self.sitePageFetch()
        return

      PageReceive = ->
        self.sitePageReceive()
        return

      PageChange= ->
        self.sitePageChange()
        return

      $(document).on "page:load", Bootup
      $(document).on "page:update", PageUpdate
      $(document).on "page:restore", PageRestore
      $(document).on 'page:fetch', PageFetch
      $(document).on 'page:receive',PageReceive
      $(document).on 'page:update', PageChange
    siteBootup: ->
      self = this
      self.initLoadingForm()
      self.initRainyDay()
      self.initUserBarDropdown()
      self.initResetPassword()
      self.initNewMusic()
      return
    sitePageUpdate: ->
      self = this
      return
    sitePageRestore: ->
      self = this
      return
    sitePageFetch: ->
      self = this
#      $('#fullpage').fullpage.destroy 'all'
      return

    sitePageReceive: ->
      self = this
      return

    sitePageChange: ->
      return
    initResetPassword: ->
      $('.reset_password').on 'click', ->
        $('.ui.test.modal').modal 'show'

    initUserBarDropdown: ->
      $('.ui.dropdown.link.item').dropdown transition: 'auto'

    initFlashMessage: ->
      setTimeout (->
        $('.ui.flash').closest('.message').addClass('animated fadeOutUp').one 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', ->
          $('#flash_message').remove()
      ), 3000

    initFullPage: ->
      $('#fullpage').fullpage
        easing: 'easeInOutQuart'
        navigationPosition: 'right'
        continuousVertical: false
        navigation: true
        slidesNavigation: true
        scrollingSpeed: 1200
        anchors: [
          'show-index'
          'show-git'
          'show-team'
          'show-login'
        ]
        sectionsColor: [
          '#f2f5f4'
          '#f2f2f2'
          '#f2f5f4'
        ]

    initNewMusic: ->
      $("#new_music_button").click ->
        $(".music-form").modal('show')



    initLoadingForm: ->
      $('#signup').click ->
        $('.ui.form').addClass "loading"
      $('#login').click ->
        $('.ui.form').addClass 'loading'
    initRainyDay: ->
      image = document.getElementById("rainyday")
      if typeof(image) != 'undefined' and image != null
        image.onload = ->
          engine = new RainyDay(image: this)
          engine.rain [[
                         3
                         2
                         2
                       ]], 100
          return
        image.crossOrigin = "anonymous"

  window.Huxi = Huxi
  return
) jQuery
$(document).ready ->
  Huxi.initFlashMessage()
#  Huxi.initFullPage()
  $(document).on 'page:change', ->
    Huxi.init()
    Huxi.siteBootup()
    return